<template>
  <view
    class="pay-item"
    :style="{
      '--bg': defThemeColor.fill,
      '--money-color': defThemeColor.text,
      '--name-color': defThemeColor.text3,
      '--border-color': defThemeColor.border2,
      '--marketing-color': '#FF0000',
      '--marketing-bg': '#FDEFED',
      '--tag-color': '#ffffff',
      '--tag-bg': 'linear-gradient(92deg, #FD6E00, #F4001C)',

      '--vip-bg': 'linear-gradient(91deg, #FFDE91, #FFF1CD, #FFDC8C)',
      '--vip-money-color': '#873B00',
      '--vip-name-color': '#522700',
      '--vip-border-color': '#F4001C',
      '--vip-marketing-color': '#ffffff',
      '--vip-marketing-bg': 'linear-gradient(90deg, #E7A321, #CD8700)',
      '--vip-tag-color': '#FFFFFF',
      '--vip-tag-bg': 'linear-gradient(91deg, #E6A220, #CD8700)',

      '--active-bg': 'linear-gradient(270deg, #FA480A, #FF0000)',
      '--active-money-color': defThemeColor.textLight,
      '--active-name-color': defThemeColor.textLight3,
      '--active-border-color': '#F4001C',
      '--active-marketing-color': '#FF0000',
      '--active-marketing-bg': '#ffffff',
      '--active-tag-color': '#FF0000',
      '--active-tag-bg': '#ffffff',
      '--active-tag-border': '#FF0000',
    }"
    :class="[active ? 'active' : '', productType === 2 ? 'vip' : '']"
    @click="myClick"
  >
    <!-- 顶部 tag -->
    <view v-if="recommendTags" class="top-tag-box">
      <text class="text">{{ recommendTags }}</text>
    </view>
    <view class="info-vessel">
      <view class="info-box">
        <view class="money-box">
          <text class="money" style="font-size: 22px; font-weight: bold">{{ productPrice }}</text>
          <text class="money" style="margin-left: 4px; font-size: 14px">{{ unit }}</text>
        </view>
        <view class="name-box">
          <text class="name">{{ productName }}</text>
        </view>
      </view>
      <view style="position: absolute; right: 0; bottom: -35px; z-index: 1; opacity: 0.5">
        <image
          :src="productType === 2 ? '/static/images/video/pay_popup_diamond.svg' : '/static/images/video/pay_popup_coin.svg'"
          style="width: 80px; height: 80px"
          mode="scaleToFill"
        ></image>
      </view>
    </view>
    <view class="marketing-desc-box">
      <text class="marketing">{{ marketingDesc }}</text>
    </view>
    <view v-if="active" key="view-2" class="click-box">
      <image src="/static/public/ico_click.png" style="width: 67px; height: 52px" mode="scaleToFill"></image>
    </view>
  </view>
</template>

<script lang="ts" setup>
  import { defThemeColor } from '@/mxp-ui/mxp-tool/theme/theme';

  defineOptions({
    name: 'pay-select-item',
  });

  defineProps({
    /** 是否选中 */
    active: { type: Boolean, required: true },
    /** 商品营销信息 */
    marketingDesc: { type: String, default: '' },
    /** 标签（如最多人选，超值等等） */
    recommendTags: { type: [Number, String], default: undefined },
    /**商品名称 */
    productName: { type: String, default: '' },
    /** 商品价格（元） */
    productPrice: { type: [Number, String], default: undefined },
    /** 商品类型：1-充值K币；2-购买会员；3-购买剧集；4-购买全集；10-K币解锁单集；11-分享解锁；12-权益券解锁；13-广告解锁； */
    productType: { type: Number, required: true },
    /** 单位 */
    unit: { type: String, required: true },
  });

  const emits = defineEmits<{
    (e: 'myClick'): void;
  }>();

  /** 点击 */
  function myClick() {
    emits('myClick');
  }
</script>

<style lang="scss" scoped>
  .click-box {
    position: absolute;
    right: 0;
    bottom: -16px;
    z-index: 4;
    animation: bounce 0.5s infinite;
  }

  .pay-item {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100px;
    text-align: center;
    background: var(--bg);
    border: 2rpx solid var(--border-color);
    border-radius: 10px;
    transition: border 0.3s;

    .info-vessel {
      position: relative;
      box-sizing: border-box;
      display: flex;
      flex: 1;
      flex-direction: column;
      align-items: flex-start;
      justify-content: center;
      width: 100%;
      padding: 0 15px;

      .info-box {
        position: relative;
        z-index: 2;
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        width: 100%;

        .money-box {
          padding: 0;

          .money {
            font-size: 14px;
            color: var(--money-color);
          }
        }

        .name-box {
          display: flex;
          align-items: center;
          justify-content: center;
          max-width: 260rpx;
          overflow: hidden;

          .name {
            overflow: hidden;
            font-size: 13px;
            color: var(--name-color);
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }

    .marketing-desc-box {
      z-index: 3;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 30px;
      overflow: hidden;
      background: var(--marketing-bg);
      border-radius: 0 0 10px 10px;

      .marketing {
        width: 280rpx;
        overflow: hidden;
        font-size: 11px;
        color: var(--marketing-color);
        text-overflow: ellipsis;
        white-space: nowrap;
        transition: color 0.3s;
      }
    }

    .top-tag-box {
      position: absolute;
      top: -10px;
      right: -1px;
      z-index: 2;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 20px;
      padding: 0 6px;
      background: var(--tag-bg);
      border-radius: 6px 6px 0;

      .text {
        max-width: 240rpx;
        overflow: hidden;
        font-size: 10px;
        color: var(--tag-color);
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    &.vip {
      background: var(--vip-bg);

      .info-vessel .info-box .name-box .name {
        color: var(--vip-name-color);
      }

      .info-vessel .info-box .money-box .money {
        color: var(--vip-money-color);
      }

      .marketing-desc-box {
        background: var(--vip-marketing-bg);

        .marketing {
          font-weight: bold;
          color: var(--vip-marketing-color);
        }
      }

      .top-tag-box {
        background: var(--vip-tag-bg);
        border: 1px solid var(--vip-tag-border);

        .text {
          color: var(--vip-tag-color);
        }
      }
    }

    &.active {
      background: var(--active-bg);
      border: 2rpx solid var(--active-border-color);

      .info-vessel .info-box .name-box .name {
        color: var(--active-name-color);
      }

      .info-vessel .info-box .money-box .money {
        color: var(--active-money-color);
      }

      .marketing-desc-box {
        background: var(--active-marketing-bg);

        .marketing {
          font-weight: bold;
          color: var(--active-marketing-color);
        }
      }

      .top-tag-box {
        background: var(--active-tag-bg);
        border: 1px solid var(--active-tag-border);

        .text {
          color: var(--active-tag-color);
        }
      }
    }
  }

  @keyframes bounce {
    0%,
    100% {
      transform: scale(1); /* 动画开始和结束时，手掌大小不变 */
    }

    50% {
      transform: scale(1.1); /* 动画中间时刻，手掌放大10% */
    }
  }
</style>
